package com.netty.java.test;

import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

import java.io.*;
import java.net.Socket;

@Slf4j
public class MyClient {

    private static final String Host = "127.0.0.1";

    private static final int Port = 10086;

    public static void main(String[] args) throws IOException {

        Socket socket = new Socket("127.0.0.1", 8888);

        OutputStream os = socket.getOutputStream();

        PrintWriter writer = new PrintWriter(os);

        String message = "hello server";

        log.info("client send message is [{}]", message);

        writer.write(message);

        writer.flush();

        BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        while (true){

            String receiveMessage = reader.readLine();

            if(!StringUtils.isEmpty(receiveMessage)){
                log.info("My Client receive message [{}]", receiveMessage);
                return;
            }
        }

    }

}
